﻿#include"game.h"

void game()
{
	char ret;
	int nan = 0;
	//初始化棋盘
	InitBoard();
  
	while (1)
	{
		system("cls");
		printf("**************************************\n");
		printf("*                                    *\n");
		printf("*请选择难度：1.简单   2.困难   3.大师*\n");
		printf("*                                    *\n");
		printf("**************************************\n");
		printf("请输入难度选择：");
		scanf("%d", &nan);
		if (nan > 3 ||  nan< 1)
		{
			printf("输入错误！重新输入！\n");
			Sleep(1000);
		}
		else break;
	}
    //打印棋盘
	TyBoard();
    //下棋
	while (1)
	{
		//玩家下
		Playermove();

		TyBoard();

		//判断输赢
		ret=IsWin();
		if (ret != 'C')
		{
			break;
		}
		system("cls");
		//电脑下
		Computemove(nan);

		TyBoard();

		ret=IsWin();
		if (ret != 'C')
		{
			break;
		}
	}
	if (ret == '*')
	{
		printf("玩家赢\n");
	}
	else if(ret=='#')
	{
		printf("电脑赢\n");
	}
	else
	{
		printf("平局\n");
	}
}

int main()
{
	int input = 3;
	do
	{
		printf("********************\n");
		printf("***1.play 0.exit***\n");
		printf("********************\n");
		printf("请选择：");
		scanf("%d", &input);
		switch (input)
		{
		case 1:printf("游戏开始\n");
			Sleep(1000);
			game();
			break;
		case 0:printf("退出游戏\n");
			break;
		default:printf("请重新选择\n");
			break;
		}
	} while (input);
	return 0;
}